package com.star.book.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.google.common.collect.Maps;
import com.star.book.entity.BookChapter;
import com.star.book.mapper.BookChapterMapper;
import com.star.book.service.IBookChapterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Mr Kong
 * @since 2020-10-03
 */
@Service
public class BookChapterServiceImpl extends ServiceImpl<BookChapterMapper, BookChapter> implements IBookChapterService {
    @Autowired
    private IBookChapterService bookChapterService;
    @Override
    public List<BookChapter> findByPage(Integer id) {
        return baseMapper.findByPage(id);
    }

    @Override
    public Map<String, Object> bookChapterMap(Integer id) {
        Map<String, Object> bookChapterMap = Maps.newHashMap();
        List<BookChapter> list = bookChapterService.list();
        int bookChapterTotalCount = list.size();
        Integer page ;
        if(bookChapterTotalCount == 0 || bookChapterTotalCount < 0){
            page = 0;
        }else{
            page = bookChapterTotalCount / 10;
            if(bookChapterTotalCount % 10 > 0){
                page=page+1;
            }
        }
        bookChapterMap.put("page",page);
        List<BookChapter> byPage = baseMapper.findByPage(id);
        bookChapterMap.put("bookChapter",byPage);
        return bookChapterMap;
    }
}
